﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Library;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Model;
using System.Text;


namespace IHISCETeim.Web.MachineSys.PartsModel
{
    public partial class PartsCatheringList : EasyUIPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除,Permission.应收帐款_冲帐 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "PartsCatheringList";
            }
        }

        #region

        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
        public string CardName
        {
            get
            {
                return GetRequestValue<string>("CardName", "");

            }
        }
       
        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.等于)]
        public string KuanXiangLeiXing
        {
            get
            {
                return GetRequestValue<string>("KuanXiangLeiXing", "");

            }
        }

        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.等于)]
        public string State
        {
            get
            {
                return GetRequestValue<string>("State", "");

            }
        }

        public string ShoukuanRiQiFrom
        {
            get
            {
                return GetRequestValue<string>("ShoukuanRiQiFrom", "");

            }
        }
        public string ShoukuanRiQiTo
        {
            get
            {
                if (string.IsNullOrEmpty(ShoukuanRiQiFrom))
                {
                    return "";
                }
                else
                {
                    string todate = GetRequestValue<string>("ShoukuanRiQiTo", "");
                    if (string.IsNullOrEmpty(todate))
                        return Convert.ToDateTime(ShoukuanRiQiFrom).AddMonths(1).ToShortDateString();
                    else
                        return todate;
                }

            }
        }
        #endregion

        /// <summary>
        /// 排序字段 值为 id
        /// </summary>
        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "Cid" : base.orderField;
            }
        }
        /// <summary>
        ///  排序方式 desc或 asc
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "desc" : base.orderDirection;
            }
        }
        protected override string SQLSort
        {
            get
            {
                return (orderField + " " + orderDirection + "  ");
            }
        }

        protected string GetSQLWhere()
        {
            string sqlwhere = QueryFiledHelper.GetSqlWhere(this);
            if (!string.IsNullOrEmpty(ShoukuanRiQiFrom))
            {
                string DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("ShoukuanRiQi", QueryOperatorsEnum.范围, ShoukuanRiQiFrom + "|" + ShoukuanRiQiTo);
                if (!string.IsNullOrEmpty(sqlwhere))
                {
                    sqlwhere += " and " + DOWNSQL;
                }
                else
                {
                    sqlwhere = DOWNSQL;
                }
            }

            return sqlwhere;
        }
        protected override string query()
        {

            // return "";
            DataTableCollection dts = PartsCatheringController.GetPagination(GetSQLWhere(), pageNum, numPerPage, SQLSort, ref TotalCount);

            return ToDataGridJson(dts[0], TotalCount, dts[1]).ToString();
        }

        protected override string delrow()
        {
            int CId = GetRequestValue<int>("CId", 0);

            bool r = PartsCatheringController.Delete(CId);
            if (r)
            {
                SuccessJson("成功删除");
                return "";
            }
            else
            {
                AlertJson("删除失败");
                return "";
            }

        }
    }
}